VintaSoft Twain ActiveX v6.0
In This Topic
    Pause Image Acquisition (Stop Feeder)
    In This Topic
    Many scanners have automatic document feeders. Some from these scanners allow to stop the feeder, i.e. pause the image acquisition process. Device_Feeder_Stop allows to stop the feeder.


    Example: Here is an example that shows how to start asynchronous image acquisition, stop the document feeder and continue asynchronous image acquisition.
    Private VSTwain1 As New VintaSoftTwain()
    Private _isScanFinished As Boolean
    Private _step As Integer
    Private _imageCount As Integer
    
    
    
    ''' <summary>
    ''' This method scans the first image, stops the document feeder,
    ''' scans the second image.
    ''' </summary>
    Private Sub ScanImage_StopFeeder_ScanImage()
        _isScanFinished = False
        _step = 0
        _imageCount = 0
    
        VSTwain1.DeviceManager_IsTwain2Compatible = True
        ' open the device manager
        If Not VSTwain1.DeviceManager_Open() Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' get the device index
        Dim deviceName As String = "KODAK Scanner: i5000"
        Dim deviceIndex As Integer = VSTwain1.DeviceManager_FindDevice(deviceName)
        If deviceIndex = -1 Then
            Throw New ApplicationException(String.Format("Device '{0}' is not found.", deviceName))
        End If
    
        ' select the device by index
        VSTwain1.DeviceManager_SelectedDeviceIndex = deviceIndex
    
        ' disable device UI
        VSTwain1.Device_ShowUI = False
        ' specify that device must be closed after scan
        VSTwain1.Device_DisableAfterAcquire = True
    
        ' open the device
        If Not VSTwain1.Device_Open Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' specify that 2 images must be acquired from scanner
        VSTwain1.Device_XferCount = 2
    
        ' subscribe to the device events
        AddHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired
        AddHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted
        AddHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed
        AddHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled
    
        ' run asynchronous image acqusition
        VSTwain1.Device_AcquireImage()
        ' wait while feeder will be stopped
        While Not _isScanFinished
            Application.DoEvents()
        End While
    
    
        If _imageCount <> 1 Then
            Throw New ApplicationException("Wrong acquired image count.")
        End If
    
        If VSTwain1.Device_State <> DEVICESTATE.DEVICESTATE_DeviceIsReadyToTransferImage Then
            Throw New ApplicationException("Feeder is NOT stopped.")
        End If
        Console.WriteLine("Feeder is stopped.")
    
    
        _isScanFinished = False
        ' continue asynchronous image acqusition
        VSTwain1.Device_AcquireImage()
        ' wait while image scan will be finished
        While Not _isScanFinished
            Application.DoEvents()
        End While
    
        If _imageCount <> 2 Then
            Throw New ApplicationException("Wrong acquired image count.")
        End If
    
        ' unsubscribe from device events
        RemoveHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired
        RemoveHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted
        RemoveHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed
        RemoveHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled
    
        ' close the device
        VSTwain1.Device_Close()
    End Sub
    
    Private Sub VSTwain1_ImageAcquired()
        Console.WriteLine("Image is acquired.")
        ' increment image count
        _imageCount += 1
    
        ' if we need stop the feeder
        If _step = 0 Then
            ' stop the feeder
            VSTwain1.Device_Feeder_Stop()
    
            ' specify that feeder is stopped
            _step = 1
            _isScanFinished = True
        End If
    End Sub
    
    Private Sub VSTwain1_ScanCompleted()
        Console.WriteLine("Scan is completed.")
        _isScanFinished = True
    End Sub
    
    Private Sub VSTwain1_ScanFailed(errorString As String)
        Console.WriteLine(String.Format("Scan is failed: {0}.", errorString))
        _isScanFinished = True
    End Sub
    
    Private Sub VSTwain1_ScanCanceled()
        Console.WriteLine("Scan is canceled.")
        _isScanFinished = True
    End Sub


    Example: Here is an example that shows how to start synchronous image acquisition, stop the document feeder and continue synchronous image acquisition.
    Private VSTwain1 As New VintaSoftTwain()
    
    
    ''' <summary>
    ''' This method scans the first image, stops the document feeder,
    ''' scans the second image.
    ''' </summary>
    Public Sub ScanImage_StopFeeder_ScanImage()
        Dim imageCount As Integer = 0
    
        VSTwain1.DeviceManager_IsTwain2Compatible = True
        ' open the device manager
        If Not VSTwain1.DeviceManager_Open() Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' get the device index
        Dim deviceName As String = "KODAK Scanner: i5000"
        Dim deviceIndex As Integer = VSTwain1.DeviceManager_FindDevice(deviceName)
        If deviceIndex = -1 Then
            Throw New ApplicationException(String.Format("Device '{0}' is not found.", deviceName))
        End If
    
        ' select the device by index
        VSTwain1.DeviceManager_SelectedDeviceIndex = deviceIndex
    
        ' disable device UI
        VSTwain1.Device_ShowUI = False
        ' specify that device must be closed after scan
        VSTwain1.Device_DisableAfterAcquire = True
    
        ' open the device
        If Not VSTwain1.Device_Open Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' specify that 2 images must be acquired from scanner
        VSTwain1.Device_XferCount = 2
    
    
        ' run synchronous image acquisition
        Dim acquireModalState1 As VSTwainLib.ACQUIREMODALSTATE = ACQUIREMODALSTATE.AcquireModalState_None
        Do
            acquireModalState1 = VSTwain1.Device_AcquireImageModal()
            Select Case acquireModalState1
                Case ACQUIREMODALSTATE.AcquireModalState_ImageAcquired
                    Console.WriteLine("Image is acquired.")
    
                    VSTwain1.AcquiredImages_Clear()
    
                    imageCount = imageCount + 1
    
                    ' stop the feeder
                    VSTwain1.Device_Feeder_Stop()
                    Exit Select
    
                Case ACQUIREMODALSTATE.AcquireModalState_ScanCompleted
                    Console.WriteLine("Scan is completed.")
                    Exit Select
    
                Case ACQUIREMODALSTATE.AcquireModalState_ScanCanceled
                    Console.WriteLine("Scan is canceled.")
                    Exit Select
    
                Case ACQUIREMODALSTATE.AcquireModalState_ScanFailed
                    Console.WriteLine(String.Format("Scan is failed: {0}.", VSTwain1.errorString))
                    Exit Select
            End Select
        Loop While acquireModalState1 <> ACQUIREMODALSTATE.AcquireModalState_None
    
    
        If imageCount <> 1 Then
            Throw New ApplicationException("Wrong acquired image count.")
        End If
    
        If VSTwain1.Device_State <> DEVICESTATE.DEVICESTATE_DeviceIsReadyToTransferImage Then
            Throw New ApplicationException("Feeder is NOT stopped.")
        End If
        Console.WriteLine("Feeder is stopped.")
    
    
        ' continue asynchronous image acquisition
        Do
            acquireModalState1 = VSTwain1.Device_AcquireImageModal()
            Select Case acquireModalState1
                Case ACQUIREMODALSTATE.AcquireModalState_ImageAcquired
                    Console.WriteLine("Image is acquired.")
    
                    VSTwain1.AcquiredImages_Clear()
    
                    imageCount = imageCount + 1
                    Exit Select
    
                Case ACQUIREMODALSTATE.AcquireModalState_ScanCompleted
                    Console.WriteLine("Scan is completed.")
                    Exit Select
    
                Case ACQUIREMODALSTATE.AcquireModalState_ScanCanceled
                    Console.WriteLine("Scan is canceled.")
                    Exit Select
    
                Case ACQUIREMODALSTATE.AcquireModalState_ScanFailed
                    Console.WriteLine(String.Format("Scan is failed: {0}.", VSTwain1.errorString))
                    Exit Select
            End Select
        Loop While acquireModalState1 <> ACQUIREMODALSTATE.AcquireModalState_None
    
        If imageCount <> 2 Then
            Throw New ApplicationException("Wrong acquired image count.")
        End If
    
        ' close the device
        VSTwain1.Device_Close()
    
    End Sub

    See Also